package com.lpdemilis.pokermanager;

import java.text.DecimalFormat;
import java.text.NumberFormat;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.util.TypedValue;
import android.widget.Button;

public class Utils {

	public static int convertToPixel(int dp, Activity activity) {
		int pixel = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
				dp, activity.getResources().getDisplayMetrics());
		return pixel;
	}
	
	public static String formatDecimal(double value, int precision){
		StringBuilder mask = new StringBuilder();
		mask.append("0.");
		
		for (int i = 0; i < precision; i++) {
			mask.append("0");
		}
		
		DecimalFormat df = new DecimalFormat(mask.toString());
		return df.format(value);
	}
	
	public static String formatCurrency(double value, Boolean removeSymbol){
		NumberFormat nf = NumberFormat.getCurrencyInstance();
		String currencyValue = nf.format(value);
		
		if(removeSymbol){
			currencyValue = currencyValue.substring(currencyValue.indexOf("$") + 1);
		}
		
		return currencyValue;
	}
	
	public static Button setButtonStyle_sorbus(Context context, Button button){
		button.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
		button.setTypeface(null, Typeface.BOLD);
		button.setPadding(10, 10, 10, 10);
		button.setTextColor(context.getResources().getColorStateList(R.color.text_color));
		button.setShadowLayer((float) 0.6, 1, 1, Color.BLACK);
		button.setBackgroundResource(R.drawable.custom_btn_sorbus);
		
		return button;
	}
	
	public static Button setButtonStyle_opal(Context context, Button button){
		button.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
		button.setTypeface(null, Typeface.BOLD);
		button.setPadding(10, 10, 10, 10);
		button.setTextColor(context.getResources().getColorStateList(R.color.text_color));
		button.setShadowLayer((float) 0.6, 1, 1, Color.BLACK);
		button.setBackgroundResource(R.drawable.custom_btn_opal);
		
		return button;
	}
}
